package top;

import entity.User;

public class RuleA implements Rule {

    private static final long newPlayer = 500L;

    private static final long winBase   = 20L;
    private static final long lostBase  = -10L;
    private static final long runBase   = -30L;
    private static final long drawBase  = 10L;

    private static Rule ruleA = new RuleA();

    public static Rule getRuleA() {
        return ruleA;
    }

    @Override
    public final long getNewPlayerInitPoints() {
        return newPlayer;
    }

    @Override
    public long[] calculatePointsWhenWinLost(User winner, User loser) {

        float rate = (float) loser.getScore() / (float) winner.getScore();

        return new long[] {
                (long)(rate * winBase),
                (long)(rate * lostBase)
        };
    }

    @Override
    public long[] calculatePointsWhenDraw(User a, User b) {
        float rateA = (float) b.getScore() / (float) a.getScore();
        float rateB = (float) a.getScore() / (float) b.getScore();

        return new long[] {
                (long)(rateA * drawBase),
                (long)(rateB * drawBase)
        };
    }

    @Override
    public long[] calculatePointsWhenRun(User winner, User runner) {

        float rateWin = (float) runner.getScore() / (float) winner.getScore();
        float rateRun = (float) runner.getScore() / (float) winner.getScore();

        return new long[] {
                (long)(rateWin * winBase),
                (long)(rateRun * runBase)
        };
    }

    public static void main(String[] args) {
        Rule rule = RuleA.getRuleA();
        User a = new User();
        User b = new User();

        a.setScore(538L);
        b.setScore(500L);

        long[] result = rule.calculatePointsWhenWinLost(a, b);

        System.out.println("a:" + result[0] + ", b:" + result[1]);
    }
}
